package common;

import business.inhospitalqc.LaunchQc;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import common.Data;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import utils.GetFileMess;

import java.io.IOException;

public class Login {
    public static final String system = "env.properties";

    public  static  Data login(){
        JSONObject json= new JSONObject();
        try {
            String userName=new GetFileMess().getValue("userName", system);
            String passwd=new GetFileMess().getValue("passwd", system);
            String orgId=new GetFileMess().getValue("orgId", system);
            RestAssured.baseURI = new GetFileMess().getValue("baseURI", system);
            RestAssured.basePath = new GetFileMess().getValue("basePath", system);
            RestAssured.port = Integer.parseInt(new GetFileMess().getValue("port", system));
            json.put("userName", userName);
            json.put("passwd", passwd);
            json.put("orgId", orgId);
        } catch ( ConfigurationException e) {
            e.printStackTrace();
        }
        System.out.println(json.toJSONString());
        Response response=RunCaseJson.runCase(json,"post","api-auth/login");
        String jsonStr= response.asString();
//        JSONObject jsonObj=JSONObject.parseObject(jsonStr);
        Loginobject loginobject= JSONObject.parseObject(jsonStr,new TypeReference<Loginobject>(){}.getType());
        Data data=  loginobject.getData();
        return data;
    }

    public  void main(String[] args) throws Exception{
        try {
            Data data= login();
            System.out.println("响应结果:");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
